package com.raja.servingStation.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.raja.servingStation.dao.FirstInsuranceOrderDao;
import com.raja.servingStation.entity.CarInfoEx;
import com.raja.servingStation.service.FirstInsuranceOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by zhangzhen on 2017/10/10.
 */
@Service
public class FirstInsuranceOrderServiceImpl implements FirstInsuranceOrderService {
    @Autowired
    private FirstInsuranceOrderDao firstInsuranceOrderDao;

    @Override
    public Object addFirstInsuranceOrder(JSONObject body) throws Exception {
        Long a = firstInsuranceOrderDao.getCarNoInSbOrders1(body.getString("carNo"));
        Long b = firstInsuranceOrderDao.getCarNoInSbOrders2(body.getString("carNo"));
        if(a==1&&b==0){
           return "一辆车只能有一次首保!";
        }
        if(a==1&&b==1){
            return firstInsuranceOrderDao.updateSbOrderState(body);
        }
        return firstInsuranceOrderDao.addFirstInsuranceOrder(body);
    }

    @Override
    public Object submitSbOrder(JSONObject body) throws Exception {
        Long id = firstInsuranceOrderDao.getCarNoInSbOrders1(body.getString("carNo"));
        if(id==1){
            return "一辆车只能有一次首保!";
        }
        return firstInsuranceOrderDao.submitSbOrder(body);
    }

    @Override
    public CarInfoEx getCarInfoByCarNo(JSONObject body) throws Exception {
        return firstInsuranceOrderDao.getCarInfoByCarNo(body.getString("carNo"));
    }
}
